class Heap{
    public int[] elem = new int[10];
    public int size;

    public Heap(int[] array) {
        for (int i = 0; i < array.length; i++) {
            elem [i] = array[i];
            size++;
        }
    }

    public void creatHeap(){
        for (int i = (size-2)/2; i >=0 ; i--) {
            ShiftDown(i,size);
        }
    }

    private void ShiftDown(int parent,int len){
        int child = parent*2+1;
        while (child<len){
            if (child+1<len&&elem[child]<elem[child+1]){
                child++;
            }

            if (elem[child]>elem[parent]){
                int tmp = elem[parent];
                elem[parent] = elem[child];
                elem[child]=tmp;
                parent = child;
                child = parent*2+1;
            } else {
                break;
            }
        }
    }
}


public class Text1 {
    public static void main(String[] args) {
        int[] array = {12,56,2,34,78,15,45,54};
        Heap heap = new Heap(array);
        heap.creatHeap();
        System.out.println("  ");
    }
}
